package cn.edu.hyit.zhao.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import cn.edu.hyit.zhao.dao.IShopDAO;
import cn.edu.hyit.zhao.entity.Shop;
import cn.edu.hyit.zhao.service.IShopService;

@Service
@Scope(value = "singleton")
public class ShopServiceImpl implements IShopService {

    @Autowired
    private IShopDAO shopDao;

    @Override
    public Shop getShop(String username) {
	return this.shopDao.selectByUsername(username);
    }

    @Override
    public List<Shop> getBranchShops(Shop shop) {
	return this.shopDao.selectByParentId(shop.getShopId());
    }

    @Override
    public int updateShop(Shop shop) {
	return this.shopDao.updateByPrimaryKeySelective(shop);
    }

    @Override
    public int saveShop(Shop shop) {
	if (null == this.shopDao.selectByUsername(shop.getUsername())) {
	    return this.shopDao.insertSelective(shop);
	} else {
	    return -1;
	}
    }

    @Override
    public Shop getShop(int shopId) {
	return this.shopDao.selectByPrimaryKey(shopId);
    }

}
